/**
 *	The NeuroCoSA Toolkit
 *	Copyright (C) 2003-6 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	2006-halloween(mk2)
 * @license	LGPL
 */

package org.stumeikle.NeuroCoSA;
import java.util.*;

import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.event.*;
import org.stumeikle.NeuroCoSA.AutoCluster.NScalar;

/** 
 * Key synapse
 * 
 * Not expected to be used much. Store an internal key. only propagate
 * vesicles whose keys match the stored exemplar. I'll try to abstract out the
 * key type but i don't know if i'll succeed. 
 *
 * stumeikle 20070211
 *
 */
public class	KeySynapse	extends SimpleSynapse
{
    KeyVesicleIF		iExemplar;


    public     KeySynapse(Neuron p,Neuron n)
    {
        super(p,n);
	iExemplar = null;
	setAdaptive(false);
    }

    /** This must be overloaded by the derived forms:
     */
    public   Vesicle	simplePropagate(Vesicle vp)
    {

	if (iExemplar !=null && vp!=null)
	{
	    try
	    {
		KeyVesicleIF	k = (KeyVesicleIF) vp;
		if (k.matches(iExemplar))
		{
		    //ok, propagate
System.out.println("Key synapse: " + this + " propagating...!");
		    setRetSignal(vp.getSignalStrength());
		    return vp;
		}
	    }
	    catch(Exception e)
	    {}
	}
System.out.println("Key synapse: " + this + " NOT propagating...!");	

	return null;
    }

    //key interface
    public	void	setExemplar( KeyVesicleIF	k )
    {
	iExemplar = k;	//or we could clone
    }
}


